# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=appstream
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.5
pkgrel=1
pkgdesc="Tools and libraries to work with AppStream metadata (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="http://www.freedesktop.org/wiki/Distributions/AppStream/"
msys2_repository_url="https://github.com/ximion/appstream"
license=('spdx:LGPL-2.1-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-curl"
  "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
  "${MINGW_PACKAGE_PREFIX}-glib2"
  "${MINGW_PACKAGE_PREFIX}-libxml2"
  "${MINGW_PACKAGE_PREFIX}-libxmlb"
  "${MINGW_PACKAGE_PREFIX}-libyaml"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
  "${MINGW_PACKAGE_PREFIX}-meson"
  "${MINGW_PACKAGE_PREFIX}-gi-docgen"
  "${MINGW_PACKAGE_PREFIX}-gperf"
  "${MINGW_PACKAGE_PREFIX}-itstool"
  "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
  "${MINGW_PACKAGE_PREFIX}-libxslt"
  "${MINGW_PACKAGE_PREFIX}-docbook-xsl"
  "${MINGW_PACKAGE_PREFIX}-gettext-tools"
)
source=("https://github.com/ximion/appstream/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
noextract=("${_realname}-${pkgver}.tar.gz")
sha256sums=('dd33b1375ba4221ffee060e2778c478e8150d7b1108c6309148f5fb1ca6e90c0')

prepare() {
  # Can't create 'appstream-1.0.4/tests/samples/compose/usr/share/locale/dir_loop/loop': File name too long
  tar -xf "${_realname}-${pkgver}.tar.gz" --exclude=tests/samples/compose/usr
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      -Dsystemd=false \
      -Dstemming=false \
      ../${_realname}-${pkgver}

  meson compile
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  meson test || warning "Tests failed"
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" meson install

  # remove html docs symlink
  rm -Rf "${pkgdir}${MINGW_PREFIX}/share/gtk-doc"

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
